Component({
  mixins: [],
  data: {
    pageShow:0,    //弹窗显示
    imgOrVideoPop:0,     //图片视频切换
    skinD:[
      {
        id:1,
        json:{
          bgImg:"https://img.alicdn.com/imgextra/i4/4161056916/O1CN01TpRyaf20xZquWXiOY_!!4161056916.jpg",
          loadBoxImg:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01TvJZOO20xZqkcMaGv_!!4161056916.png",
          bgImg2:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01PpyDfs20xZqulsX91_!!4161056916.jpg",
          ptd:"https://img.alicdn.com/imgextra/i4/4161056916/O1CN01G2i7mb20xZqvBsRfn_!!4161056916.png",
          sltc:"https://img.alicdn.com/imgextra/i3/4161056916/O1CN01WnybD220xZqi9JADZ_!!4161056916.png"
        },
        logo:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01BRThYr20xZqo8N3k5_!!4161056916.jpg",
        title:"日常主题"
      },
      // {
      //   id:2,
      //   json:{
      //     bgImg:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01jUMeKw20xZqiXFs4K_!!4161056916.jpg",
      //     loadBoxImg:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01TvJZOO20xZqkcMaGv_!!4161056916.png",
      //     ptd:"https://img.alicdn.com/imgextra/i1/4161056916/O1CN01tweasB20xZqkhdK4v_!!4161056916.png",
      //     sltc:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN013QJC7L20xZqe73wrg_!!4161056916.png"
      //   },
      //   logo:"https://isv.alibabausercontent.com/00000000/imgextra/i2/4161056916/O1CN01wYzdmf20xZqXNMDCe_!!4161056916-0-isvtu-00000000.jpg",
      //   title:"高级主题"
      // },
      // {
      //   id:3,
      //   json:{
      //     bgImg:"https://img.alicdn.com/imgextra/i3/4161056916/O1CN018gK8LA20xZqnWhtdZ_!!4161056916.png",
      //     loadBoxImg:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN01TvJZOO20xZqkcMaGv_!!4161056916.png",
      //     ptd:"https://img.alicdn.com/imgextra/i1/4161056916/O1CN01tweasB20xZqkhdK4v_!!4161056916.png",
      //     sltc:"https://img.alicdn.com/imgextra/i2/4161056916/O1CN013QJC7L20xZqe73wrg_!!4161056916.png"
      //   },
      //   logo:"https://isv.alibabausercontent.com/00000000/imgextra/i2/4161056916/O1CN01wYzdmf20xZqXNMDCe_!!4161056916-0-isvtu-00000000.jpg",
      //   title:"日常主题2"
      // }
    ],
    skin:1,         //皮肤主题默认选择
    nowdate:"",      //当前时间
    day:"0",
    hour:"0",
    second:"0",
    //数据格式
    title:"",       //活动名称
    startTime:"",   //开始时间
    endTime:"",     //结束时间
    cftitle:false,
    isCommit:{
      grassProductId1:false,
      grassProductId2:false,
      grassProductId3:false,
    },
    inputValue:"",
    imgData:{
      
    },

    //种草图片or视频
    grassProductId1:{
      
    },
    grassProductId2:{
      
    },
    grassProductId3:{
      
    },
    
    //弹窗回显
    showPopImg:"",

    //图片上传框判断数组
    boxArr:[
      {id:"logoId",width:300,height:300},
      {id:"headImageId",width:600,height:600},
      {id:"bigPrizeImageId",width:482,height:136},
      {id:"pictureId",width:600,height:600},
      {id:"pictureId1",width:600,height:600},
      {id:"pictureId2",width:600,height:600},
    ],

    lunIndex:0,// 预览轮播

    tc:false
  },


  props: {},

  onInit(){
    
  },


  didMount() {
    

    this.$page.informationPage = this
    

    this.setData({

      imgData:{},
      grassProductId1:{
        grassProductId1:"",
        jumpLink:""
      },
      grassProductId2:{
        grassProductId2:"",
        jumpLink:""
      },
      grassProductId3:{
        grassProductId3:"",
        jumpLink:""
      },

    })

    //console.log("1516516161",this.data.skinD)

    setTimeout(()=>{console.info("skin",this.data.skinD)},1000)
    setTimeout(()=>{console.info("getNow",this.data.nowdate)},1000);

    this.setData({
      timer:this.data.nowdate
    })

    // this.setData({
    //   nowdate:[this.data.nowdate, '2019-02-02']
    // })
    
  },
  didUpdate() {},
  didUnmount() {},
  methods: {

    //日期组件时间处理

    
    

    //跳转素材
    jumpSucai(){
      my.qn.navigateToWebPage({
        url: "https://www.yuque.com/docs/share/b46ca188-6ddb-4614-8f7e-09b9c50fc8d5?# 《相关素材》",
        success: res => {
        },
        fail: res => {
        }
      })
    },

    //图片或视频弹窗
    ivPop(){
      

    },

    //取消
   cancel(){

    if(this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`] && this.data.isCommit[`grassProductId${this.data.index}`]){
     this.setData({
        imgOrVideoPop:0,
        // showPopImg:"",
      //   [`grassProductId${this.data.index}`]:{
      //   jumpLink:""
      // }
    })
    }else{
       this.setData({
        imgOrVideoPop:0,
        showPopImg:"",
        [`grassProductId${this.data.index}`]:{
        jumpLink:""
      }
    })
 
    }
   
//console.log(this.data[`grassProductId${this.data.index}`])
},

    //图片
    img(){
      this.setData({
        pageShow:0
      })
    },

    //视频
    vf(){
      this.setData({
        pageShow:1
      })
    },

    //获取标题
    changeinut(e){
      //console.log(e);
      this.setData({
        [e.currentTarget.dataset.name]:e.detail.value
      })

      if(e.currentTarget.dataset.name == "title"){
        //my.alert({content:11111})
        this.$page.getActiveName(e.detail.value)
      }
    },

    //获取开始时间与结束时间
    changedate(e){

      console.info(e)

      this.setData({
        day:'0',
        hour:'0',
        second:'0',
        startTime:e.detail.value[0],   //开始时间
        endTime:e.detail.value[1],     //结束时间
      })
      
      if(e.detail.value[0] && e.detail.value[1]){
        
        this.getTime(e.detail.value[0],e.detail.value[1]);
        
      }

    },

    // 时间计算
    getTime(start,end){

      let time=new Date(end).getTime()-new Date(start).getTime();
      let day = Math.floor(time/(1000*60*60*24));  //计算天数
      let hour = Math.floor(time/(1000*60*60)%24);  //计算小时数
      let second= Math.floor(time/(1000*60)%60);    //计算分数

      this.setData({
        day:day,
        hour:hour,
        second:second
      })

    },

      // 种草图片上传
    testUploadFile1(eve){

      let _this = this
     
      //console.log(this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`])

      my.chooseImage({  
        sourceType:["album"],
        success: images => {

          console.log("上传成功",images.apFilePaths[0])

          my.getImageInfo({

            src:images.apFilePaths[0],

            success:(res)=>{
              
              if(res.width !=548 || res.height != 548 ){

               my.alert({title:'图片尺寸不符',content:`请上传548*548的图片`})
              }else{
                getApp().cloud.file.uploadFile({  
                  filePath: images.apFilePaths[0],  
                  fileType: 'image'
                }).then((res)=>{
                              
                  let obj = _this.data[eve.currentTarget.dataset.id];

                  obj[eve.currentTarget.dataset.id] = res.url;

                  console.log("obj******",obj)

                  _this.setData({
                    [eve.currentTarget.dataset.id]:obj
                  })

                  console.log(_this.data.grassProductId1)

                  _this.setData({
                    showPopImg:_this.data[`grassProductId${_this.data.index}`][`grassProductId${_this.data.index}`]
                  })

                  console.log(_this.data.showPopImg)

                })
              }
            }
          })


          
          
        }  
      })
    },

    //处理跳转链接
    onChangejumplink(eve){
      //console.log("1111",eve)
      let obj=this.data[`grassProductId${this.data.index}`];
      
      obj[eve.currentTarget.dataset.id] = eve.detail.value;

      this.setData({
        [`grassProductId${this.data.index}`]:obj
      })

      //console.log(this.data)

    },



    
    // 上传图片
    testUploadFile(eve){

     

      // if(this.data[eve.currentTarget.dataset.id]){
      //   //先删除原本有的
      //   getApp().cloud.file.deleteFile({  
      //     fileId: this.data[eve.currentTarget.dataset.id]
      //   }).then((res)=>{
      //     this.setData({
      //       [eve.currentTarget.dataset.id]:'',
      //       [eve.currentTarget.dataset.url]:''
      //     })
      //   }) 

    

      // }else{

      let _this = this
      let boxArr = this.data.boxArr
      let obj = this.data.imgData;

       _this.setData({
        lunIndex:eve.currentTarget.dataset.current
      })

        my.chooseImage({
          sourceType:["album"],  
          success: images => { 
            my.getImageInfo({
              src:images.apFilePaths[0],
              success:(res)=>{

                for(let i = 0;i<boxArr.length;i++){
                  if(boxArr[i].id==eve.currentTarget.dataset.id){
                    if(res.width != boxArr[i].width || res.height != boxArr[i].height){
                      my.alert({title:'图片尺寸不符',content:`请上传${boxArr[i].width}*${boxArr[i].height}的图片`})
                      // return
                    }else{

                      getApp().cloud.file.uploadFile({  
                        filePath: images.apFilePaths[0],  
                        fileType: 'image'
                      }).then((res)=>{

                        obj[eve.currentTarget.dataset.url] = res.url
                        _this.setData({
                          imgData:obj
                        })

                      })

                    }
                  }
                }
              }
            })
            

            
            // let img = new Image();
            // img.src = images.apFilePaths[0];
            // img.onload = function(){
            //   console.log(boxArr)
            //     for(let i = 0;i<boxArr.length;i++){
            //       if(boxArr[i].id==eve.currentTarget.dataset.id){
            //         if(img.width>boxArr[i].width || img.height>boxArr[i].height){
            //           my.showToast({content:"图片尺寸不符，请重新上传"})
            //           return
            //         }else{
            //             getApp().cloud.file.uploadFile({  
            //               filePath: images.apFilePaths[0],  
            //               fileType: 'image'
            //             }).then((res)=>{

                          
            //               obj[eve.currentTarget.dataset.url] = res.url
            //               _this.setData({
            //                 imgData:obj
            //               })


            //             })
            //         }
            //       }
            //     }
            // }

            

          }  
        })

      // }
    },

    //点击了那套皮肤
    skin(e){
      //console.log(e)
  
      this.setData({
        skin:e.currentTarget.dataset.index
      })
    },

    //点击了那个种草框
    grassindex(e){

      // my.alert({content:e.currentTarget.dataset.index})


      // if(this.data[`grassProductId${e.currentTarget.dataset.index}`].jumplink){

      // }

      this.setData({
        imgOrVideoPop:1,
        index:e.currentTarget.dataset.index,
        showPopImg:"",
        inputValue:'',
        tc:true,
      })

      if(this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`]){
        if((this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`].indexOf('mp4')>0 || this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`].indexOf('MP4')>0) && this.data.isCommit[`grassProductId${this.data.index}`]){
          this.setData({
            inputValue:this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`]
          })
          console.log("你好")
        }else{
          this.setData({
            inputValue:''
          })
          console.log("我不好")
        }
      }
     

      if(this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`] && this.data.isCommit[`grassProductId${this.data.index}`]){
    
        this.setData({

          showPopImg:this.data[`grassProductId${this.data.index}`][`grassProductId${this.data.index}`],
          jumpLink:this.data[`grassProductId${this.data.index}`].jumplink

        })
      }else{

        this.setData({

          showPopImg:"",
          jumpLink:""

        })
      }

      console.log("======>",this.data)
      
    },


    //提交
    submit(){

      this.setData({
        imgOrVideoPop:0,
        
      })
      let iscommit = this.data.isCommit
      iscommit[`grassProductId${this.data.index}`] = true
      this.setData({
        isCommit:iscommit
      })

      console.log(iscommit)
      //console.log("all",this.data)
    }
    
    
    

  },
});
